package com.portalEsporteClubeBahia.app.bo;

import java.util.List;

import com.portalEsporteClubeBahia.app.ApplicationException;
import com.portalEsporteClubeBahia.app.dao.StadiumDAO;
import com.portalEsporteClubeBahia.app.vo.StadiumVO;

public class StadiumBO {
	
	private StadiumDAO stadiumDAO;
	
	public StadiumBO() throws ApplicationException{
		try {
			stadiumDAO = new StadiumDAO();
		} catch (ApplicationException e) {
			throw new ApplicationException(e);
		}
	}
	
	public List<StadiumVO> findAll() throws ApplicationException{
		try{
			return stadiumDAO.findAll();
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}
	
	public void insert(StadiumVO stadium) throws ApplicationException{
		try{
			
			if(stadium.getName()==null || stadium.getName().equals("")){
				throw new ApplicationException("MISSING NAME!");
			}
			
			stadiumDAO.insert(stadium);
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}
	
	public void update(StadiumVO stadium) throws ApplicationException{
		try{
			
			if(stadium.getId()==null){
				throw new ApplicationException("MISSING ID!");
			}
			if(stadium.getName()==null || stadium.getName().equals("")){
				throw new ApplicationException("MISSING NAME!");
			}
			
			stadiumDAO.update(stadium);
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}

	public void delete(StadiumVO stadium) throws ApplicationException{
		try{
			
			if(stadium.getId()==null){
				throw new ApplicationException("MISSING ID!");
			}
			
			stadiumDAO.delete(stadium);
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}
	
	public StadiumVO findByPrimaryKey(StadiumVO filter) throws ApplicationException{
		try{
			return stadiumDAO.findByPrimaryKey(filter);
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}
	
	public List<StadiumVO> findByFilter(StadiumVO filter) throws ApplicationException{
		try{
			return stadiumDAO.findByFilter(filter);
		}catch(ApplicationException e){
			throw new ApplicationException(e);
		}
	}

}
